﻿Public Class frmWBRackMng
    Dim dtMng As DataTable
    Dim objDB As New clsDBWbRackMng
    Dim dtStatus As DataTable
    Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
        If txtLotNo.Text.Trim = "" Then Exit Sub

        dgvData.AutoGenerateColumns = False
        colStatus.DataSource = dtStatus
        colStatus.DisplayMember = "name"
        colStatus.ValueMember = "id"

        dtMng = objDB.GetAllData(txtLotNo.Text.Trim.ToUpper)
        If dtMng.Rows.Count > 0 Then
            dgvData.DataSource = dtMng
        End If

    End Sub

    Private Sub createStatsu()

        dtStatus = New DataTable("status")
        Dim dc1 As New DataColumn("id", Type.GetType(“System.String”))
        Dim dc2 As New DataColumn("name", Type.GetType(“System.String”))

        dtStatus.Columns.Add(dc1)
        dtStatus.Columns.Add(dc2)

        Dim dr As DataRow
        dr = dtStatus.NewRow
        dr("id") = "0"
        dr("name") = "未着工"
        dtStatus.Rows.Add(dr)
        dr = dtStatus.NewRow
        dr("id") = "1"
        dr("name") = "临时着工"
        dtStatus.Rows.Add(dr)
        dr = dtStatus.NewRow
        dr("id") = "2"
        dr("name") = "临时完工"
        dtStatus.Rows.Add(dr)

    End Sub

    Private Sub frmWBRackMng_Load(sender As Object, e As EventArgs) Handles Me.Load
        createStatsu()
    End Sub

    Private Sub dgvData_CellEnter(sender As Object, e As DataGridViewCellEventArgs) Handles dgvData.CellEnter
        If TypeOf dgvData.Columns(e.ColumnIndex) Is DataGridViewComboBoxColumn And e.RowIndex <> -1 Then
            SendKeys.Send("{F4}")
        End If
    End Sub

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        If IsNothing(dgvData.DataSource) Then Exit Sub
        If ope.Text.Trim = "" Then
            MsgBox(getMsgStr("MSG00002", "作业者"))
            ope.Focus()
            ope.Select()
            Exit Sub
        End If
        Dim dt As DataTable = dgvData.DataSource
        If IsNothing(dt.GetChanges) Then Exit Sub

        If objDB.saveChangedValue(txtLotNo.Text.Trim, ope.Text.Trim, dt) = 0 Then
            MsgBox(getMsgStr("MSG00019", "数据库"))
        End If
    End Sub

    Private Sub dgvData_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles dgvData.CellValueChanged
        If (e.ColumnIndex = 0 Or e.ColumnIndex = 1 Or e.ColumnIndex = 2) And e.RowIndex <> -1 Then
            dgvData.Item(e.ColumnIndex, e.RowIndex).Value = dgvData.Item(e.ColumnIndex, e.RowIndex).Value.ToString.ToUpper
        End If
    End Sub

    Private Sub dgvData_CellPainting(sender As Object, e As DataGridViewCellPaintingEventArgs) Handles dgvData.CellPainting
        If e.RowIndex > -1 Then
            If IsNothing(dgvData.DataSource) Then Exit Sub
            If DBNullTOblank(dgvData.Rows(e.RowIndex).Cells("colStatus").Value) = "2" Then
                dgvData.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Brown
            End If
        End If

    End Sub

    Public Function DBNullTOblank(obj As Object) As String
        DBNullTOblank = IIf(IsDBNull(obj), "", obj)
    End Function

End Class